*********************************************************
*About the Stata syntaxes:
*The do files contain Stata syntaxes. Datasets containing information on student borrowers are available only through restricted-use license from the United States Department of Education. 
*Contents of licensed files – such as variable statistics, variable descriptions, and numbers of observations – are protected by Section 183 of the Educational Sciences Reform Act of 2002. 
*Therefore, syntaxes related to variable names are redacted to a generic form. 

*Please see the "README" file for how to apply for the licensed data.
**********************************************************

***Table 1***
clear
use File1
include Controls

* Panel A
ivreg2 switch $control0 [pw=$weight], cluster($cluster)

ivreg2 switch $control1 [pw=$weight], cluster($cluster) 

ivreg2 switch $control2 [pw=$weight], cluster($cluster) 

ivreg2 switch $control3 [pw=$weight], cluster($cluster) 

ivreg2 switch $control4 [pw=$weight], cluster($cluster)

* Panel B
ivreg2 switch $control3_1 [pw=$weight], cluster($cluster)

ivreg2 switch $control3_2 [pw=$weight], cluster($cluster)

ivreg2 switch $control3_3 [pw=$weight], cluster($cluster) 

ivreg2 switch $control5 [pw=$weight], cluster($cluster) 

ivreg2 switch $control6 [pw=$weight], cluster($cluster) 

ivreg2 switch $control5c [pw=$weight], cluster($cluster) 

ivreg2 switch $control6c [pw=$weight], cluster($cluster) 


***Table 2***
* The following generates Table 2 and Figure 1 in one file

run "Main1.do"

***Table 3***
clear
use File4

include Controls

ivreg2 switch $control3_2 unsub female_unsub white_unsub [pw=$weight], cluster($cluster) 

ivreg2 switch $control3_3 unsub female_unsub white_unsub [pw=$weight], cluster($cluster) 

ivreg2 switch $control5 unsub female_unsub white_unsub [pw=$weight], cluster($cluster) 

ivreg2 switch $control6 unsub female_unsub white_unsub [pw=$weight], cluster($cluster) 


***Table 4***
clear
use File5

ivreg2 female s1 s2 s3 [pw=$weight], cluster (school)
test _b[s1]=_b[s2]
test _b[s1]=_b[s3]
test _b[s2]=_b[s3]

// Use reghdfe here because the large number of student original dummies; Using ivreg2 becomes cumbersome
reghdfe female s1 s2 s3  [pw=$weight], a(loanyear) cluster(school)
test _b[s1]=_b[s2]
test _b[s1]=_b[s3]
test _b[s2]=_b[s3]

reghdfe female s1 s2 s3 amount [pw=$weight], a(loantype loanyear level) cluster(school)
test _b[s1]=_b[s2]
test _b[s1]=_b[s3]
test _b[s2]=_b[s3] 

reghdfe female s1 s2 s3 amount [pw=$weight], a(loantype loanyear level student_loc) cluster (school)
test _b[s1]=_b[s2]
test _b[s1]=_b[s3]
test _b[s2]=_b[s3] 

ivreg2 white s1 s2 s3 [pw=$weight], cluster (school)
test _b[s1]=_b[s2]
test _b[s1]=_b[s3]
test _b[s2]=_b[s3]
 
reghdfe white s1 s2 s3  [pw=$weight], a(loanyear) cluster(school)
test _b[s1]=_b[s2]
test _b[s1]=_b[s3]
test _b[s2]=_b[s3]

reghdfe white s1 s2 s3 amount [pw=$weight], a(loantype loanyear level) cluster(school)
test _b[s1]=_b[s2]
test _b[s1]=_b[s3]
test _b[s2]=_b[s3] 

reghdfe white s1 s2 s3 amount [pw=$weight], a(loantype loanyear level student_loc) cluster (school)
test _b[s1]=_b[s2]
test _b[s1]=_b[s3]
test _b[s2]=_b[s3]


***Table 5***
clear
use File1

include Controls

* Panel A
preserve
replace switch=switch*100
forvalue i=1(1)4{ //servicer ids are randomized to "1" to "4"
ivreg2 switch if servicer==`i' [pw=$weight], cluster($cluster)
}

forvalue i=1(1)4{//servicer ids are randomized to "1" to "4"
ivreg2 switch if servicer==`i' & female==1 [pw=$weight], cluster($cluster)
ivreg2 switch if servicer==`i' & female==0 [pw=$weight], cluster($cluster)
}

forvalue i=1(1)4{//servicer ids are randomized to "1" to "4"
ivreg2 switch if servicer==`i' & white==1 [pw=$weight], cluster($cluster)
ivreg2 switch if servicer==`i' & white==0 [pw=$weight], cluster($cluster)
}
restore

*Panel B
*Output imported to excel to convert explained difference to a ratio of observed difference
preserve
gen group=1 if servicer==4
replace group=2 if servicer==1
keep if group!=.

oaxaca switch female white [pw=$weight], by(group) detail 

oaxaca switch female white fin_literacy_high busSTEMmajor attain_deg17 [pw=$weight], by(group) detail 

oaxaca switch female white fin_literacy_high busSTEMmajor attain_deg17 ln_age veteran marriedornot amt risk  [pw=$weight], by(group) detail 
restore

preserve
gen group=1 if servicer==3
replace group=2 if servicer==1
keep if group!=.

oaxaca switch female white [pw=$weight], by(group) detail 

oaxaca switch female white fin_literacy_high busSTEMmajor attain_deg17 [pw=$weight], by(group) detail 

oaxaca switch female white fin_literacy_high busSTEMmajor attain_deg17 ln_age veteran marriedornot amt risk  [pw=$weight], by(group) detail 
restore


preserve
gen group=1 if servicer==2
replace group=2 if servicer==1
keep if group!=.

oaxaca switch female white [pw=$weight], by(group) detail 

oaxaca switch female white fin_literacy_high busSTEMmajor attain_deg17 [pw=$weight], by(group) detail 

oaxaca switch female white fin_literacy_high busSTEMmajor attain_deg17 ln_age veteran marriedornot amt risk  [pw=$weight], by(group) detail 
restore


***Table 6***
clear
use File6

include Controls

ivreg2 switch $control5 female_dec white_dec female_dec_interact [pw=$weight], cluster($cluster)

ivreg2 switch $control6 female_dec white_dec female_dec_interact [pw=$weight], cluster($cluster)

ivreg2 switch $control5 female_dec white_dec white_dec_interact [pw=$weight], cluster($cluster) 

ivreg2 switch $control6 female_dec white_dec white_dec_interact [pw=$weight], cluster($cluster) 


***Table 7***
clear
use File7

include Controls

ivreg2 switch $control5 [pw=$weight], cluster($cluster)  

ivreg2 switch $control6 [pw=$weight], cluster($cluster)  

ivreg2 switch $control5c [pw=$weight], cluster($cluster)  

ivreg2 switch $control6c [pw=$weight], cluster($cluster)  

***Table 8***
clear
use File8

include Controls

ivreg2 dlq_after_loan $control_deliq5 [pw=$weight], cluster($cluster)  

ivreg2 dlq_after_loan switch [pw=$weight], cluster($cluster)  

ivreg2 dlq_after_loan switch $control_deliq5 [pw=$weight], cluster($cluster)  

ivreg2 dlq_after_loan switch $control_deliq6 [pw=$weight], cluster($cluster)  
